
// show trailer 
// and others

#include "../tablet_server/sstable.hpp"

#include <iostream>

using namespace std;
using namespace xbase;

// command sstable-filename
int main(int argc, char **argv)
{
	LOG4CPLUS_DO_CONFIG("../../conf/log4cplus.tablet_server.conf");
	xbase::fs::init("../../conf/gfs_client.conf");
	sstable_block_cache_manager::init_instance(5 * 1024 * 1024);

	{
		if(argc < 2)
		{
			cout << argv[0] << " <path>" << endl;
			return 0;
		}
		std::string path = argv[1]; // path name
		
		sstable::pointer cur = sstable::load(path,
						     path,
						     path,//parent_path + "/deleted." + fs::get_name(info),
						     "",
						     "",
						     0,
						     ST_NORMAL_SSTABLE);
		std::cout << cur->to_string() << std::endl;

		sstable_block_cache block;
		block_entry entry;
		std::size_t counter = 0;
		for(std::pair<size_t, size_t> pos(0, 0);
		    cur->get_entry(block, entry, pos);
		    cur->advance_index(pos), ++counter)
		{
			std::cout << "[ " << counter << " ] "
				  << "(" << pos.first << ", " << pos.second << ") "
				  << (std::string)(*entry.m_key->row()) << " "
				  << (std::string)(*entry.m_key->column()) << " "
				  << entry.m_key->timestamp()->get() << " "
				  << (std::string)(*entry.m_value) << std::endl;
		}
		
	}

	sstable_block_cache_manager::reset_instance();
	
	return 0;
}
